package com.chen.util;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Month;
import cn.hutool.core.date.Week;
import com.chen.dao.pojo.Course;
import java.util.Date;

/**
 * @Author:chenao
 * @DATE:2022/3/12 16:50
 */

public class DateUtils {

    public static String formatDateString(String originTime){
        String formatPattern="yyyy-MM-dd HH:mm:ss";
        Date date = new Date(originTime);
        return DateUtil.format(date, formatPattern);
    }

    public static String formatCourseTime(Course course){
        String startTime = course.getStartTime();
        String endTime = course.getEndTime();
        DateTime startDate = DateUtil.parse(startTime,"yyyy-MM-dd HH:mm:ss");
        DateTime endDate = DateUtil.parse(endTime, "yyyy-MM-dd HH:mm:ss");
        String week = DateUtil.dayOfWeekEnum(startDate).toChinese("周");
        String month = (DateUtil.month(startDate)+1)+"月";
        String day = DateUtil.dayOfMonth(startDate)+"日";
        String startHour = formatHourString(startDate);
        String endHour = formatHourString(endDate);
        String time = week+" "+month+day+" "+startHour+"-"+endHour;
        return time;
    }

    public static String formatHourString(DateTime dateTime){
        String formatPattern="HH:mm";
        Date date = dateTime.toJdkDate();
        return DateUtil.format(date, formatPattern);
    }

}